package Problem2;

import java.util.ArrayList;

public class Main {

	public static void main(String[] args) {
		int answer = 0;
		for (int num: fibonacci(new ArrayList<Integer>(),4000000)){
			if (num % 2 == 0)
				answer += num;
		}
		System.out.println(answer);
	}
	public static ArrayList<Integer> fibonacci(ArrayList<Integer> answer, int stoppingPoint){
		if (answer.size() == 0) {
			answer.add(1);
			answer.add(2);
			return fibonacci(answer, stoppingPoint);
		}
		
		int term1 = answer.get(answer.size() - 1);
		if (term1 >= stoppingPoint)
			return answer;
		
		int term2 = answer.get(answer.size() - 2);

		answer.add(term1 + term2);
	
		return fibonacci(answer, stoppingPoint);
	}
}
